<?php


namespace app\services;

use app\lib\exception\AuthException;
use app\lib\exception\ParamException;
use app\lib\exception\ServiceException;

use app\model\Users;
use app\Request;
use app\utils\JWTUtil;

use think\captcha\facade\Captcha;
use think\facade\Cache;
use think\facade\Session;




class UserService
{
    public function add($role, $username, $password){
        $usersDao = new Users();

        if (!empty($usersDao->where('username', '=', $username)->find())) {
            throw new ParamException('用户名存在');
        }

        $usersDao->username = $username;

        return $usersDao->find( $usersDao->insertGetId([
            'username' => $username,
            'password' => $usersDao->setSaltPwd($password),
            'role' => $role,
        ]));
    }




//
//    public function getToken($token)
//    {
//        return Cache::store('redis')->get($token);
//    }
//    public function delToken($token)
//    {
//        return Cache::store('redis')->delete($token);
//    }
//




}
